package maple.core.contextproviders;

import maple.core.ContextProvider;
import maple.util.Context;
import maple.util.Sensor;

public class SimpleLampState extends ContextProvider
{
	private double _threshold;

	public SimpleLampState()
	{
		super( 1 );

		// from Consumer
		_preconditions.add( Sensor.Type.PHIDGET_LIGHT.toString() ); 
		_postcondition = Context.Type.LAMPSTATE.toString();

		_threshold = -1;
	}

	protected void setup()
	{
		super.setup();

		_threshold = Double.parseDouble( _arguments[ 1 ] );
	}

	protected String interpret()
	{
		String ls = _preconditions.get( 0 );
		double lamp_state = Double.parseDouble( Sensor.toString( ls, _perceptions.get( ls ) ) );
		
		if( lamp_state < 0 )
		{
			return ContextProvider.State.UNKNOWN.toString();
		}
		else if( lamp_state > _threshold )
		{
			return Context.LampState.ON.toString();
		}
		return Context.LampState.OFF.toString();
	}
}
